package com.situ.mall.admin.controller;


import com.situ.mall.admin.entity.User;
import com.situ.mall.admin.service.IUserService;
import com.situ.mall.admin.vo.LayuiTableVO;
import com.situ.mall.admin.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Arrays;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author membergpf
 * @since 2023-03-18
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    IUserService userService;

    @PostMapping("/delete")
    @ResponseBody
    public void deleteUser(Integer id)
    {
        userService.removeById(id);
    }

    @GetMapping("/userSetting")
    public String setting(){
        System.out.println("usersetting");
        return "userSetting";
    }

    @GetMapping("/list")
    @ResponseBody
    public LayuiTableVO list(String keyword ,@RequestParam Integer page, @RequestParam Integer limit ){
        return userService.list(keyword,page, limit);
    }
    @GetMapping("/index")
    public String index() {
        return "user";
    }

    @PostMapping("/save")
    @ResponseBody
    public ResultVO save(User user) {
        return userService.add(user);
    }
    @PostMapping("/deleteByPrimaryKeys")
    @ResponseBody
    public void selectById(@RequestParam("ids[]") Integer[] ids){
        userService.removeByIds(Arrays.asList(ids));

    }
    @PostMapping("/edit")
    @ResponseBody
    public ResultVO edit(Integer id){
        return userService.edit(id);
    }

    @PostMapping("/editInformation")
    @ResponseBody
    public ResultVO editInformation( String username ,String sex, String tel){
        return userService.editInformation(username,sex,tel);
    }

}
